$OpenBSD: patch-src_pkcs11_misc_c,v 1.1 2016/11/24 09:54:51 dcoppa Exp $

commit 12f402616050e6ac943217b2170e865c1a297e77
Author: Jakuje <jakuje@gmail.com>
Date:   Mon Oct 10 22:21:46 2016 +0200

Fix Coverity remarks

--- src/pkcs11/misc.c.orig	Fri Jun  3 11:19:51 2016
+++ src/pkcs11/misc.c	Thu Nov 24 09:58:03 2016
@@ -178,11 +178,10 @@ CK_RV push_login_state(struct sc_pkcs11_slot *slot,
 	struct sc_pkcs11_login *login = NULL;
 
 	if (!sc_pkcs11_conf.atomic || !slot) {
-		r = CKR_OK;
-		goto err;
+		return CKR_OK;
 	}
 
-	login = (struct sc_pkcs11_login *) malloc(sizeof *login);
+	login = (struct sc_pkcs11_login *) calloc(1, sizeof *login);
 	if (login == NULL) {
 		goto err;
 	}
@@ -199,12 +198,15 @@ CK_RV push_login_state(struct sc_pkcs11_slot *slot,
 		goto err;
 	}
 
+	login = NULL;
 	r = CKR_OK;
 
 err:
-	if (r != CKR_OK && login) {
-		sc_mem_clear(login->pPin, login->ulPinLen);
-		free(login->pPin);
+	if (login) {
+		if (login->pPin) {
+			sc_mem_clear(login->pPin, login->ulPinLen);
+			free(login->pPin);
+		}
 		free(login);
 	}
 
